/*
 * This file is part of aKoustiK.

 * aKoustiK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * aKoustiK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with aKoustiK.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PLAYLIST_H
#define PLAYLIST_H

#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QReadWriteLock>

#include <item.h>

/**
  Class responsible for playlist handling.
  This class hould be as simple as possible and handle only real list operations.
  All IO work or advanced notification logic should not go here.
  */
class Playlist : public QObject {
    Q_OBJECT

public:

    // constructors/destructors:
    Playlist(const QList<Item*>& currentItems, const QString& currentName, QObject* parent);
    ~Playlist();

    // logic const methods (not using const because we're using QReadWriteLock):
    /** Current size of playlist. If playlist is empty - 0 will be returned. */
    int size();
    /** Take item at index. If no such item - 0 will be returned. */
    Item* at(int index);
    /** Check if list is empty. */
    bool isEmpty();
    /** Find the index of item in playlist. */
    int indexOf(Item* item);
    /** Get the copy of current list.
      This method is used for background operations,
      they can work with copy in any way they want
      without locking actual playlist. */
    QList<Item*> items();

    // name:
    const QString& name() const;
    void setName(const QString& value);

public slots:
    void removeItem(int index);
    void appendItems(const QList<Item*> items);

private:
    /** Real list of items used to store them. */
    QList<Item*> internalItemsList;
    /** Name of current playlist. */
    QString playlistName;
    /** List operations are using this lock to ensure correct work in concurrent env. */
    QReadWriteLock lock;

signals:
    /** Signal emited when current item removed using "remove-current" action.
      This action invoked not from mainWindow UI, so mainWindow UI should
      connect to this signal. */
    void removingItem(int index,Item* item);
    /** Signal emited every time playlist is changed.
      InternalStorage should save current playlist if it was changed. */
    void playlistChanged();

};

#endif
